package com.lsa.letcode.the111.minDepthOfTheBt;

import com.lsa.letcode.common.TreeNode;

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
public class Solution {
    public int minDepth(TreeNode root) {
        if (root == null){
        	return 0;
        }
        else if (root.left == null && root.right == null) {
        	return 1;
        }
        else {
        	int leftMin = Integer.MAX_VALUE;
        	if (root.left != null){
        		leftMin = minDepth(root.left);
        	}
        	int rightMin = Integer.MAX_VALUE;
        	if (root.right != null){
        		rightMin = minDepth(root.right);
        	}
        	return 1 + Math.min(leftMin, rightMin);
        }
    }
}